package day15.test05;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Xiao
 * @date 2021/8/9
 */
public class Server05 {
    /**
     * 5. 使用TCP完成数据的发送和接收
     *     发送端发送，接收端接收
     *     接收端回复，发送端接收
     */
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(12321);
        Socket so = ss.accept();
        BufferedReader br = new BufferedReader(new InputStreamReader(so.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
        }
        so.shutdownInput();
        OutputStream os = so.getOutputStream();
        os.write("你喜欢大海...\r\n我爱过你...".getBytes());
        so.close();
        ss.close();
    }
}
